/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.trsjh.db.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;



/**
 * Hibernate Utility class with a convenient method to get Session Factory object.
 *
 * @author nb
 */
public class HibernateUtil {
    private static final EntityManagerFactory entityManagerFactory;
    static {
        try {
        	entityManagerFactory = Persistence.createEntityManagerFactory("myGlass_JPA");
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial EntityManagerFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static EntityManagerFactory getEntityManagerFactory() {
        return entityManagerFactory;
    }
    public static void colseEntityManagerFactory(){
    	if(entityManagerFactory!=null){
    		 entityManagerFactory.close();
    	}
    }
    public static EntityManager createEntityManager(){
    	return entityManagerFactory.createEntityManager();
    }
}
